<template>
  <el-dialog
    title="成果导出"
    append-to-body
    :visible.sync="dialogVisible"
    width="450px"
    :before-close="beforeClose"
  >
    <el-form :model="form" ref="form" :rules="rules">
      <el-form-item label-width="70px" label="账期：" prop="year">
        <el-date-picker
          v-model="form.year"
          type="year"
          size="small"
          placeholder="选择账期"
          value-format="yyyy"
          style="width: 230px"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label-width="70px" label="区域：" prop="areaId">
        <dx-cascader :area_id.sync="form.areaId" size="small" style="width: 230px" />
      </el-form-item>
    </el-form>

    <div slot="footer">
      <div class="dialog-footer" style="text-align: center">
        <el-button size="mini" type="primary" @click="handle_export"
          >导出</el-button
        >
        <el-button size="mini" @click="beforeClose">取消</el-button>
      </div>
    </div>
  </el-dialog>
</template>
<script>
import { getCookie } from "@/common/js/cookie";
import { downLoadExcelParams } from "@/utils/zipdownload.js"
export default {
  data(){
    return {
      dialogVisible: false,
      form: {
        year: "",
        areaId: "",
        logId: "",
      },
      rules: {
        year: [{required: true, message: '必填', trigger: "blur"}],
        areaId: [{required: true, message: '必填', trigger: "blur"}],
      },
    }
  },
  methods: {
    init(row){
      this.form.logId = row.logId;
      this.dialogVisible = true;
    },
    beforeClose(){
      this.dialogVisible = false;
      this.$refs.form.resetFields();
    },
    // 导出
    async handle_export() {
      await this.$refs["form"].validate();
      await downLoadExcelParams(
        "/compileIncome/exportBudgetcalCulation",
        { token: getCookie("token"), ...this.form },
        "计算数据"
      );
      this.beforeClose();
    },
  }
}
</script>